package com.zephyr.vchcenter.service.impl;

import org.apache.log4j.Logger;
import com.hiaward.bpm.model.Process;
import com.hiaward.bpm.model.ProcessNode;
import com.hiaward.bpm.service.ProcessManager;
import com.hiaward.bpm.service.ProcessTransactionManager;
import com.zephyr.vchcenter.bean.Voucher;
import com.zephyr.vchcenter.service.ICreateProcessService;
import com.hiaward.bpm.web.config.WebProcessConfig;
/**
 * @author zhaoyunxiao ICreateProcessService的具体实现类
 */
public class CreateProcessImpl implements ICreateProcessService {
	private final Logger log=Logger.getLogger(CreateProcessImpl.class);
	public void createProcess(Voucher voucher) {
		try {
		ProcessTransactionManager.getInstance().beginTransaction();
		ProcessManager processManager = ProcessManager.getInstance();
		Process process = processManager.processCreate("Vchzms-P");
		process.getContext().setAttribute("WEB_PROCESS_NAME", "WebProcessVchzms");
		log.debug(process.getProcessDefinitionName());
		ProcessNode processNode = process.getReadyNodeByNodeName("createTask");
		//Voucher newVoucher = new Voucher();
			if (voucher.getAccno() != null) {
				processNode.setInputParameterValue("CreateVoucherAction", "accno",
						voucher.getAccno());
			}
			if (voucher.getAmount() != null) {
				processNode.setInputParameterValue("CreateVoucherAction", "amount",
						voucher.getAmount());
			}
			if(voucher.getFimgid()!=null) {
				processNode.setInputParameterValue("CreateVoucherAction", "fimgid",
						voucher.getFimgid());
			}
			if (voucher.getBimgid()!= null) {
				processNode.setInputParameterValue("CreateVoucherAction", "bimgid",
						voucher.getBimgid());
			}
			if(voucher.getExchno()!=null){
				processNode.setInputParameterValue("CreateVoucherAction", "exchno",
						voucher.getExchno());
			}
			if (voucher.getVchno()!= null) {
				processNode.setInputParameterValue("CreateVoucherAction", "vchno",
						voucher.getVchno());
			}
			if (voucher.getVchtype()!= null) {
				processNode.setInputParameterValue("CreateVoucherAction", "vchtype",
						voucher.getVchtype());
			}
			if (voucher.getVchdate()!= null) {
				processNode.setInputParameterValue("CreateVoucherAction", "vchdate",
						voucher.getVchdate());
			}
			/*processNode.setInputParameterValue("CreateVoucherAction", "WEB_PROCESS_NAME",
					"WebProcessVchzms");*/
			processNode.execute();
			ProcessTransactionManager.getInstance().endTransaction();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		Voucher voucher=new Voucher();
		voucher.setAccno("100100");
		voucher.setAmount("33333");
		voucher.setVchno("22");
		voucher.setVchtype("12");
		voucher.setVchdate("2009-09-09");
		voucher.setBrbank("222");
		voucher.setExchno("111111111");
		voucher.setFimgid("3333");
		voucher.setBimgid("000000");
		ICreateProcessService createpro=new CreateProcessImpl();
		createpro.createProcess(voucher);
	}

}
